home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / nuweb / msdos / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-02  |  3.3 KB  |  145 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. #ifndef FALSE
  6. #define FALSE 0
  7. #endif
  8. #ifndef TRUE
  9. #define TRUE (!0)
  10. #endif
  11. typedef struct scrap_node {
  12.   struct scrap_node *next;
  13.   int scrap;
  14. } Scrap_Node;
  15. typedef struct name {
  16.   char *spelling;
  17.   struct name *llink;
  18.   struct name *rlink;
  19.   Scrap_Node *defs;
  20.   Scrap_Node *uses;
  21.   int mark;
  22.   char tab_flag;
  23.   char indent_flag;
  24.   char debug_flag;
  25. } Name;
  26.  
  27. int tex_flag;      /* if FALSE, don't emit the .tex file */
  28. int output_flag;   /* if FALSE, don't emit the output files */
  29. int compare_flag;  /* if FALSE, overwrite without comparison */
  30. char *command_name;
  31. char *source_name;  /* name of the current file */
  32. int source_line;    /* current line in the source file */
  33. Name *file_names;
  34. Name *macro_names;
  35. Name *user_names;
  36.  
  37. void pass1();
  38. void write_tex();
  39. void write_files();
  40. void source_open(); /* pass in the name of the source file */
  41. int source_get();   /* no args; returns the next char or EOF */
  42. void init_scraps();
  43. int collect_scrap();
  44. int write_scraps();
  45. Name *collect_file_name();
  46. Name *collect_macro_name();
  47. Name *collect_scrap_name();
  48. Name *name_add();
  49. Name *prefix_add();
  50. char *save_string();
  51. void reverse_lists();
  52. void *arena_getmem();
  53. void arena_free();
  54.  
  55.  
  56. void main(argc, argv)
  57.      int argc;
  58.      char **argv;
  59. {
  60.   int arg = 1;
  61.   tex_flag = TRUE;
  62.   output_flag = TRUE;
  63.   compare_flag = TRUE;
  64.   command_name = argv[0];
  65.   while (arg < argc) {
  66.     char *s = argv[arg];
  67.     if (*s++ == '-') {
  68.       {
  69.         char c = *s++;
  70.         while (c) {
  71.           switch (c) {
  72.             case 'c': compare_flag = FALSE;
  73.                       break;
  74.             case 'o': output_flag = FALSE;
  75.                       break;
  76.             case 't': tex_flag = FALSE;
  77.                       break;
  78.             case 'v': printf("nuweb version 0.6\n");
  79.                       break;
  80.             default:  fprintf(stderr, "%s: unexpected argument ignored.  ",
  81.                               command_name);
  82.                       fprintf(stderr, "Usage is: %s [-cot] file...\n",
  83.                               command_name);
  84.                       break;
  85.           }
  86.           c = *s++;
  87.         }
  88.       }
  89.       arg++;
  90.     }
  91.     else break;
  92.   }
  93.   if (arg < argc)
  94.     do {
  95.       {
  96.         char source_name[100];
  97.         char tex_name[100];
  98.         {
  99.           char *p = argv[arg];
  100.           char *q = source_name;
  101.           char *trim = q;
  102.           char *dot = NULL;
  103.           char c = *p++;
  104.           while (c) {
  105.             *q++ = c;
  106.             if (c == '/') {
  107.               trim = q;
  108.               dot = NULL;
  109.             }
  110.             else if (c == '.')
  111.               dot = q - 1;
  112.             c = *p++;
  113.           }
  114.           *q = '\0';
  115.           if (dot) {
  116.             *dot = '\0';
  117.             sprintf(tex_name, "%s.tex", trim);
  118.             *dot = '.';
  119.           }
  120.           else {
  121.             sprintf(tex_name, "%s.tex", trim);
  122.             *q++ = '.';
  123.             *q++ = 'w';
  124.             *q = '\0';
  125.           }
  126.         }
  127.         {
  128.           pass1(source_name);
  129.           if (tex_flag)
  130.             write_tex(source_name, tex_name);
  131.           if (output_flag)
  132.             write_files(file_names);
  133.           arena_free();
  134.         }
  135.       }
  136.       arg++;
  137.     } while (arg < argc);
  138.   else {
  139.     fprintf(stderr, "%s: expected a file name.  ", command_name);
  140.     fprintf(stderr, "Usage is: %s [-cot] file-name...\n", command_name);
  141.     exit(-1);
  142.   }
  143.   exit(0);
  144. }
  145.